package leetcode.editor.week.week310;

import java.util.HashSet;
import java.util.Set;

// 6177. 子字符串的最优划分
// https://leetcode.cn/problems/optimal-partition-of-string/submissions/
class Solution6177 {
    // 滑动窗口
    public int partitionString(String s) {
        int r = 0;
        Set<Character> set = new HashSet<>();
        int res = 1;
        while(r < s.length()) {
            char c = s.charAt(r);
            if(!set.contains(c)) {
                r++;
                set.add(c);
            } else {
                res++;
                set.clear();
            }
        }
        return res;
    }
}